import { ElLoading } from 'element-plus'
import type { LoadingOptions } from 'element-plus'

export interface LoadingParentElement extends HTMLElement {
  vLoadingAddClassList?: () => void
}
let loading: ReturnType<typeof ElLoading.service> | undefined
export function useLoading(isShow: boolean, text?: string, options?: LoadingOptions) {
  if (isShow) {
    loading = ElLoading.service({
      lock: true,
      text: text || 'Loading...',
      ...options,
    })
  }
  else {
    loading?.close()
    loading = undefined
  }
  return loading
}
